<template>
  <div class="">
    <div>
      <h6>商家详情信息</h6>
      <button @click="$router.go(-1)">回到上一页</button>
      <h4>{{ info.address }}</h4>
      <h5>{{ info.name }}</h5>
    </div>

    <div style="display: flex">
      <van-sidebar v-model="active" style="width: 20%">
        <van-sidebar-item
          v-for="(item, index) in menu"
          :key="index"
          :title="item.name"
        />
      </van-sidebar>

      <ul style="flex: 1">
        <li v-for="item in menu[active].foods" :key="item.id">
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { getInfo, getMenu } from "../utils/ele";
export default {
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const data = reactive({
      info: {},
      menu: [],
      active: 0, //当前选的下标
    });
    let id = route.params.id;
    //根据这个id要发送两个请求
    // 一个是 商家的详情信息
    // 一个是菜单

    getInfo(id).then((res) => {
      console.log(res);
      data.info = res;
    });
    //获取商家详情

    getMenu(id).then((res) => {
      console.log(res);
      data.menu = res;
    });
    //获取菜单
    return { ...toRefs(data) };
  },
};
</script>

<style lang="scss"></style>
